package com.gy.yemall.yemallproduct.controller;

import java.net.BindException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.gy.common.vaild.AddGroup;
import com.gy.common.vaild.UpdateGroup;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.gy.yemall.yemallproduct.entity.BrandEntity;
import com.gy.yemall.yemallproduct.service.BrandService;
import com.gy.common.utils.PageUtils;
import com.gy.common.utils.R;

import javax.validation.Valid;


/**
 * 品牌
 *
 * @author ye
 * @email 2900801226@qq.com
 * @date 2021-09-30 16:28:53
 */
@RestController
@RequestMapping("yemallproduct/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @GetMapping("/list")
    // @RequiresPermissions("yemallproduct:brand:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    // @RequiresPermissions("yemallproduct:brand:info")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);
        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("yemallproduct:brand:save")
    public R save(@Validated(AddGroup.class) @RequestBody BrandEntity brand){
        brandService.save(brand);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("yemallproduct:brand:update")
    public R update(@Validated(UpdateGroup.class) @RequestBody BrandEntity brand){

        // brandService.updateById(brand);
        brandService.updateBrandAndC_B_Relation(brand);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("yemallproduct:brand:delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }

}
